package org.libl.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 定义分页数据的javaBean: 封装分页的数据信息
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageBean<T> {
    private Integer currentPage;//表示当前页码数,从页面传递过来的
    private Integer pageSize;//每页显示的固定数据条数
    private List<T> list;//每页显示的具体数据
    private Integer totalCount;//参与分页总的数据条数
    private Integer totalPage;//计算出来的总的页数
    private Integer firstPage;//页面显示的第一个页码数字
    private Integer endPage;//页面显示的最后一个页码数字
    private Integer lastPage;//上一页
    private Integer nextPage;//下一页

    public Integer getCurrentPage(){
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage){
        this.currentPage = currentPage;
    }

    public Integer getPageSize(){
        return pageSize;
    }

    public void setPageSize(Integer pageSize){
        this.pageSize = pageSize;
    }

    public List<T> getList(){
        return list;
    }

    public void setList(List<T> list){
        this.list = list;
    }

    public Integer getTotalCount(){
        return totalCount;
    }

    public void setTotalCount(Integer totalCount){
        this.totalCount = totalCount;
    }

    public Integer getTotalPage(){
        totalPage=(totalCount%pageSize==0)?
                totalCount/pageSize:totalCount/pageSize+1;
        return totalPage;
    }

    public void setTotalPage(Integer totalPage){
        this.totalPage = totalPage;
    }

    public Integer getFirstPage(){
        if(totalPage<=10){
            firstPage=1;
            endPage=totalPage;
        }else{
            if(currentPage-5<=1){
                firstPage=1;
                endPage=10;
            }else if(currentPage-5>1 && currentPage+4<totalPage){
                firstPage=currentPage-5;
                endPage=currentPage+4;
            } else if(currentPage+4>=totalPage){
                firstPage=totalPage-9;
                endPage = totalPage;
            }
        }
        return firstPage;
    }

    public Integer getEndPage(){
        return endPage;
    }


    public Integer getLastPage(){
        if(currentPage==1){
            lastPage=1;
        }else{
            lastPage=currentPage-1;
        }
        return lastPage;
    }

    public Integer getNextPage(){
        if(currentPage==totalPage){
            nextPage=totalPage;
        }else{
            nextPage=currentPage+1;
        }
        return nextPage;
    }


}

















